package com.hqd527.qdshop.serviceproduct.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hqd527.qdshop.product.SpuInfo;
import com.hqd527.qdshop.result.Result;
import com.hqd527.qdshop.serviceproduct.service.ManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @author 太优秀
 * @date 2022/4/7 14:28
 * @description
 */
@RestController
@RequestMapping("/admin/product/")
@CrossOrigin
@Api(value="SPU管理",tags = "SPU管理")
public class SpuManageController {

    @Autowired
    private ManageService manageService;


    @ApiOperation("分页查询SPU商品信息")
    @PostMapping("getSpuInfoByPage/{current}/{limit}")
    public Result getSpuInfoByPage(@PathVariable("current") Long current,
                                   @PathVariable("limit")Long limit,
                                   @RequestBody SpuInfo spuInfo){
        IPage<SpuInfo> papeModel = manageService.getSpuInfoByPage(current, limit, spuInfo);
        // 查询出来的数据列表
        List<SpuInfo> currentList = papeModel.getRecords();
        // 总记录数
        long total = papeModel.getTotal();
        // 封装数据
        HashMap<String, Object> map = new HashMap<>();
        map.put("currentList",currentList);
        map.put("total",total);

        return Result.ok(currentList);
    }

}
